<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="LoginCss/LoginIndex.css">
    <script src="js/jquery-3.4.1.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script>
        $.ajax({
            url:'login/validateLogin.php',
            type:'post',
            data:{},
            dataType:'json',
            async:false,
            success:function (data) {
                if(data.code===200){
                    location.href="主页.html";
                }
            }
        });
    </script>
</head>
<body>
<div class="login">
    <div class="loginPad">
        <div class="titlePad">
        <b>欢迎登录学生选课系统</b>
        </div>
        <div class="labelPad">
            <span class="starMark">*</span>
            <label for="username">用户名</label>
            <input type="text" id="username">
        </div>
        <div class="labelPad">
            <span class="starMark">*</span>
            <label class="rework" for="password">密码</label>
            <input type="password" id="password">
        </div>
        <div class="labelPad">
            <input type="checkbox" id="auto"><label for="auto" class="reworkLogin">下次自动登录</label>
            <a href="注册.html">注册</a>
        </div>
        <div class="labelPad">
            <button type="button" id="loginBtn">登&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp录</button>
        </div>
    </div>
</div>
</body>
<script>
    $("#loginBtn").click(function () {
        $.ajax({
            url:'login/loginX.php',
            type:'post',
            data:{
                name:$("#username").val(),
                password:$("#password").val(),
                auto:$("#auto").prop("checked") ? 1 :0
            },
            async:true,
            dataType:'json',
            success:function (data) {
                if(data.code===200){
                    //  如果登录成功，不需要写cookie，而是后端自动写cookie 会自动完成，只需要进行跳转
                    location.href="主页.html"
                }
            },
            error:function (error) {

            }
        });
    });
</script>
</html>